﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Cintellect.Web.Mvc.Sitemap
{
	public class SitemapProfileCollection : ConfigurationElementCollection
	{
		public override ConfigurationElementCollectionType CollectionType
		{
			get
			{
				return ConfigurationElementCollectionType.AddRemoveClearMap;
			}
		}

		public SitemapProfileElement this[int index]
		{
			get { return (SitemapProfileElement)BaseGet(index); }
			set
			{
				if (BaseGet(index) != null)
				{
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
			}
		}

		private int index = -1;
		private ConfigurationElement item = null;

		public SitemapProfileElement this[string key]
		{
			get { return (SitemapProfileElement)BaseGet(key); }
			set
			{
				item = BaseGet(key);
				if (item != null)
				{
					index = BaseIndexOf(item);
					BaseRemoveAt(index);
				}
				BaseAdd(index, value);
				index = -1;
				item = null;
			}
		}

		public void Add(SitemapProfileElement element)
		{
			BaseAdd(element);
		}

		public void Clear()
		{
			BaseClear();
		}

		protected override ConfigurationElement CreateNewElement()
		{
			return new SitemapProfileElement();
		}

		protected override object GetElementKey(ConfigurationElement element)
		{
			return ((SitemapProfileElement)element).Name;
		}

		public void Remove(SitemapProfileElement element)
		{
			BaseRemove(element.Name);
		}

		public void Remove(string name)
		{
			BaseRemove(name);
		}

		public void RemoveAt(int index)
		{
			BaseRemoveAt(index);
		}

	}
}
